<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace Jacov\JacovBundle\Controller;

use Jacov\JacovBundle\Controller\MainController;
use Jacov\JacovBundle\Entity\Gallery;
use Jacov\JacovBundle\Model\GalleryModel;
use Symfony\Component\Finder\Finder;

class GalleryController extends MainController
{
    private $_GalleryModel;
	private $file1 = '/home/jacov/jacov.com.ua/www/web/bundles/jacov/gallery/';
	private $file2 = __DIR__;
	
    public function indexAction($page)
    {
        $picture = array();
        $finder = new Finder();
        if (isset($_SERVER['HTTP_CLIENT_IP'])
        || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
        || in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))) 
        {
            $this->file1 = $this->file2.'./../../../../web/bundles/jacov/gallery/';
        }
        $finder->files()->in($this->file1.$page.'/');
        foreach ($finder as $file) {
            $picture[] = $file->getRelativePathname();
        }

        $this->_GalleryModel = new GalleryModel($this->getDoctrine()->getManager());
        return $this->render(
            'JacovJacovBundle:Content:gallery.html.twig',
            array(
                    'picture'  =>  $picture,
                    'page'     =>  $page,
                    'count'    =>  0
                )    
        );
    }
}

